package com.hlxt.nj.busi.dao.impl;

import com.hlxt.nj.base.dao.BaseDao;
import com.hlxt.nj.busi.dao.TCourseDAO;
import com.hlxt.nj.busi.model.TCourse;
import com.hlxt.nj.busi.model.TCourseCriteria;
import com.hlxt.nj.common.PageBean;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.beanutils.PropertyUtils;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.ResponseBody;


@Repository
public class TCourseDAOImpl extends BaseDao implements TCourseDAO {

    public TCourseDAOImpl() {
        super();
    }

    public int countByExample(TCourseCriteria example) {
        Integer count = (Integer)  getSqlMapClientTemplate().queryForObject("T_COURSE.countByExample", example);
        return count;
    }

    public int deleteByExample(TCourseCriteria example) {
        int rows = getSqlMapClientTemplate().delete("T_COURSE.deleteByExample", example);
        return rows;
    }

    public int deleteByPrimaryKey(String id) {
        TCourse _key = new TCourse();
        _key.setId(id);
        int rows = getSqlMapClientTemplate().delete("T_COURSE.deleteByPrimaryKey", _key);
        return rows;
    }

    public void insert(TCourse record) {
        getSqlMapClientTemplate().insert("T_COURSE.insert", record);
    }

    public void insertSelective(TCourse record) {
        getSqlMapClientTemplate().insert("T_COURSE.insertSelective", record);
    }

    @SuppressWarnings("unchecked")
    public List<TCourse> selectByExample(TCourseCriteria example) {
        List<TCourse> list = getSqlMapClientTemplate().queryForList("T_COURSE.selectByExample", example);
        return list;
    }

    public TCourse selectByPrimaryKey(String id) {
        TCourse _key = new TCourse();
        _key.setId(id);
        TCourse record = (TCourse) getSqlMapClientTemplate().queryForObject("T_COURSE.selectByPrimaryKey", _key);
        return record;
    }

    public int updateByExampleSelective(TCourse record, TCourseCriteria example) {
        UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
        int rows = getSqlMapClientTemplate().update("T_COURSE.updateByExampleSelective", parms);
        return rows;
    }

    public int updateByExample(TCourse record, TCourseCriteria example) {
        UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
        int rows = getSqlMapClientTemplate().update("T_COURSE.updateByExample", parms);
        return rows;
    }

    public int updateByPrimaryKeySelective(TCourse record) {
        int rows = getSqlMapClientTemplate().update("T_COURSE.updateByPrimaryKeySelective", record);
        return rows;
    }

    public int updateByPrimaryKey(TCourse record) {
        int rows = getSqlMapClientTemplate().update("T_COURSE.updateByPrimaryKey", record);
        return rows;
    }

    @SuppressWarnings("unchecked")
    public void selectPageBeanByExample(TCourseCriteria example, PageBean pageBean) {
        example.setFirstResult(pageBean.getRsFirstNumber() - 1);
        example.setMaxResults(pageBean.getLength());
        Integer count = (Integer)  getSqlMapClientTemplate().queryForObject("T_COURSE.countByExample", example);
        List<TCourse> list = getSqlMapClientTemplate().queryForList("T_COURSE.selectByExample", example);
        pageBean.setTotalRecords(count);
        pageBean.setResults(list);
    }

    @SuppressWarnings("unchecked")
    public void selectPageBean(TCourse record, PageBean pageBean) {
        Map<String,Object> condition = new HashMap<String,Object>();
        try {
            condition = PropertyUtils.describe(record);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        condition.put("firstResult", pageBean.getRsFirstNumber() - 1);
        condition.put("endResult", pageBean.getLength() + pageBean.getRsFirstNumber() - 1);
        condition.put("maxResults", pageBean.getLength());
        Integer count = (Integer)  getSqlMapClientTemplate().queryForObject("T_COURSE.countByPo", record);
        List<TCourse> list = getSqlMapClientTemplate().queryForList("T_COURSE.selectPageBeanByMap", condition);
        pageBean.setTotalRecords(count);
        pageBean.setResults(list);
    }

    public int count(TCourse record) {
        Integer count = (Integer)  getSqlMapClientTemplate().queryForObject("T_COURSE.countByPo", record);
        return count;
    }

    @SuppressWarnings("unchecked")
    public List<TCourse> select(TCourse record) {
        Map<String,Object> condition = new HashMap<String,Object>();
        try {
            condition = PropertyUtils.describe(record);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        condition.put("firstResult", null);
        condition.put("endResult", null);
        condition.put("maxResults", null);
        List<TCourse> list = getSqlMapClientTemplate().queryForList("T_COURSE.selectPageBeanByMap", condition);
        return list;
    }

    protected static class UpdateByExampleParms extends TCourseCriteria {
        private Object record;

        public UpdateByExampleParms(Object record, TCourseCriteria example) {
            super(example);
            this.record = record;
        }

        public Object getRecord() {
            return record;
        }
    }
}